<!-- 考核管理 -->
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: 'assessment/assessmentList' }">考核管理</el-breadcrumb-item>
      <el-breadcrumb-item>考核管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="assessmentInline" class="surgery-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="assessmentInline.roomNumber" placeholder="输入考核名称"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input size="small" v-model="assessmentInline.deptNo" placeholder="请输入考核类型"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" @click="search">搜索</el-button>
        <el-button size="small" type="primary" @click="assessmentEdit()">新增</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="assessmentList" highlight-current-row v-loading="loading" border
      element-loading-text="拼命加载中" style="width: 95.2%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column align="center" prop="name" label="考核名称" width="200">
      </el-table-column>
      <el-table-column align="center" prop="type" label="考核类型" width="200">
      </el-table-column>
      <el-table-column align="center" prop="date" label="考核日期" width="100">
      </el-table-column>
      <el-table-column align="center" prop="startTime" label="开始时间" width="100">
      </el-table-column>
      <el-table-column align="center" prop="endTime" label="结束时间" width="200">
      </el-table-column>
      <el-table-column align="center" prop="participantCount" label="参与人数" width="200">
      </el-table-column>
      <el-table-column align="center" prop="status" label="考核状态" width="260">
      </el-table-column>
      <el-table-column align="center" label="操作" width="240">
        <template slot-scope="scope">
          <el-button size="mini" @click="assessmentEdit(scope.$index, scope.row)">查看</el-button>
          <el-button size="mini" type="danger" @click="deleteAssessment(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="assessmentVisible" width="30%" @click="closeDialog">
      <el-form label-width="120px" :model="assessment" :rules="assessmentRules" ref="assessment">
        <el-form-item label="考核名称" prop="name">
          <el-input size="small" v-model="assessment.name" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="考核类型" prop="type">
          <el-input size="small" v-model="assessment.type" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="考核日期" prop="date">
          <el-input size="small" v-model="assessment.date" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-input size="small" v-model="assessment.startTime" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-input size="small" v-model="assessment.endTime" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="参与人数" prop="participantCount">
          <el-input size="small" v-model="assessment.participantCount" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="考核状态" prop="status">
          <el-input size="small" v-model="assessment.status" auto-complete="off" placeholder="请输入"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title"
          @click="submitForm('assessment')">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import { surgeryRoom, assessmentSave, assessmentDelete } from '../../api/basisMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      assessmentVisible: false, //控制编辑页面显示与隐藏
      title: '查看',
      assessment: {
        id: '',
        name: '',
        type: '',
        date: '',
        startTime: '',
        endTime: '',
        participantCount: '',
        status: '',
        token: localStorage.getItem('logintoken')
      },
      // assessmentRules表单验证
      assessmentRules: {
        assessmentBankName: [
          { required: true, message: '请输入考核名称', trigger: 'blur' }
        ],
        assessmentBankId: [{ required: true, message: '请输入考核类型', trigger: 'blur' }]
      },
      assessmentInline: {
        page: 1,
        limit: 10,
        token: localStorage.getItem('logintoken')
      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
      userparm: [], //搜索权限
      assessmentList: [], //数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  created() {
    this.getdata(this.assessmentInline)
  },
  methods: {
    // 获取数据列表
    getdata(parameter) {
      this.loading = true
      // 模拟数据开始
      let res = {
        code: 0,
        msg: null,
        count: 36,
        data: [
          {
            id: 1,
            name: '内科临床思维考核',
            type: '案例分析',
            date: '2024-03-15',
            startTime: '09:00',
            endTime: '10:30',
            participantCount: 45,
            status: '已完成'
          },
          {
            id: 2,
            name: '外科临床思维考核',
            type: '实操考核',
            date: '2024-03-20',
            startTime: '14:00',
            endTime: '16:00',
            participantCount: 40,
            status: '已完成'
          },
          {
            id: 3,
            name: '妇产科临床思维考核',
            type: '选择题',
            date: '2024-03-25',
            startTime: '08:30',
            endTime: '10:00',
            participantCount: 38,
            status: '已完成'
          },
          {
            id: 4,
            name: '儿科临床思维考核',
            type: '简答题',
            date: '2024-04-01',
            startTime: '13:30',
            endTime: '14:45',
            participantCount: 43,
            status: '已完成'
          },
          {
            id: 5,
            name: '神经科临床思维考核',
            type: '病例分析',
            date: '2024-04-05',
            startTime: '09:15',
            endTime: '11:00',
            participantCount: 56,
            status: '已完成'
          },
          {
            id: 6,
            name: '眼科临床思维考核',
            type: '判断题',
            date: '2024-04-10',
            startTime: '10:00',
            endTime: '11:00',
            participantCount: 36,
            status: '已完成'
          },
          {
            id: 7,
            name: '耳鼻喉科临床思维考核',
            type: '填空题',
            date: '2024-04-15',
            startTime: '14:15',
            endTime: '15:45',
            participantCount: 40,
            status: '已完成'
          },
          {
            id: 8,
            name: '皮肤科临床思维考核',
            type: '问诊模拟',
            date: '2024-04-20',
            startTime: '08:45',
            endTime: '10:15',
            participantCount: 35,
            status: '进行中'
          },
          {
            id: 9,
            name: '肿瘤科临床思维考核',
            type: '综合题',
            date: '2024-04-25',
            startTime: '11:30',
            endTime: '13:00',
            participantCount: 48,
            status: '未开始'
          },
          {
            id: 10,
            name: '精神科临床思维考核',
            type: '综合题',
            date: '2024-04-29',
            startTime: '13:00',
            endTime: '14:30',
            participantCount: 53,
            status: '未开始'
          },
        ]
      }
      this.loading = false
      this.assessmentList = res.data
      this.pageparm.currentPage = this.assessmentInline.page
      this.pageparm.pageSize = this.assessmentInline.limit
      this.pageparm.total = res.count
      // 测试环境  模拟数据结束  

      /***
       *  正式环境环境 调用接口
       */
      surgeryRoom(parameter)
        .then(res => {
          this.loading = false
          if (res.success == false) {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.assessmentList = res.data
            // 分页赋值
            this.pageparm.currentPage = this.assessmentInline.page
            this.pageparm.pageSize = this.assessmentInline.limit
            this.pageparm.total = res.count
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.assessmentInline.page = parm.currentPage
      this.assessmentInline.limit = parm.pageSize
      this.getdata(this.assessmentInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.assessmentInline)
    },
    //添加、编辑
    assessmentEdit: function (index, row) {
      this.assessmentVisible = true
      if (row != undefined && row != 'undefined') {
        this.title = '查看'
        this.assessment.name = row.name
        this.assessment.type = row.type
        this.assessment.date = row.date
        this.assessment.startTime = row.startTime
        this.assessment.endTime = row.endTime
        this.assessment.participantCount = row.participantCount
        this.assessment.status = row.status
      } else {
        this.title = '添加'
        this.assessment.name = ''
        this.assessment.type = ''
        this.assessment.date = ''
        this.assessment.startTime = ''
        this.assessment.endTime = ''
        this.assessment.surgeryTime = ''
        this.assessment.status =''
      }
    },
    // 保存
    submitForm(editData) {
      this.$refs[editData].validate(valid => {
        if (valid) {
          assessmentSave(this.assessment)
            .then(res => {
              this.assessmentVisible = false
              this.loading = false
              if (res.success) {
                this.getdata(this.assessmentInline)
                this.$message({
                  type: 'success',
                  message: '考核保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.assessmentVisible = false
              this.loading = false
              this.$message.error('考核保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },
    // 删除
    deleteAssessment(index, row) {
      this.$confirm(`确定要删除吗?`, '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          assessmentDelete(row.assessmentBankId)
            .then(res => {
              if (res.success) {
                this.$message({
                  type: 'success',
                  message: '已删除!'
                })
                this.getdata(this.assessmentInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('删除失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 关闭编辑、增加弹框
    closeDialog() {
      this.assessmentVisible = false
    }
  }
}
</script>

<style scoped>
.surgery-search {
  margin-top: 20px;
}
</style>

 
 